I would love to have it featured on the Wiki, I'm certain that a lot of other users would like to see an example like this - it's a pretty common method to hold tools.
I have attached a snippet that only has definitions, and a sequence of events that I would like to execute (suggestions are very welcome). I haven't attempted to write any code yet as I'm likely to go down a path that doesn't make much sense (I have limited aptitude for programming!).
Also attached is a photo of the tool changing apparatus (the holder) to give some context to my sequence of events described in the code snippet.
Also, as the machine currently only has 4 tool holders, some code to check for a tool holder that is invalid or not specified would be good. Ideas for this are welcomed.
#include "KMotionDef.h"
//-----------------------------------------
// LINEAR TOOL CHANGING
//-----------------------------------------
//---------Absolute position of tool holders
#define HOLDER_1 (X100Y1300Z-200)
#define HOLDER_2 (X200Y1300Z-200)
#define HOLDER_3 (X300Y1300Z-200)
#define HOLDER_4 (X400Y1300Z-200)
#define TOOL_HEIGHT_PLATE (X50Y50) //absolute position of the tool height setting plate
#define TOOL_CHANGE_SAFE_POS (X250Y1200) // absolute position to move to that
// is permanently unobstructed, and safe to move down in Z
#define Y_AXIS_SAFE_DISTANCE 100 // distance in mm to approach tool holder
//---------
//--------- Spindle IO bits
#define CLAW_EJECT 58 // IO bit to eject tool from spindle (KONNECT OUTPUT 10)
#define SPINDLE_CLEAN 59 // IO bit to blow air out of spindle taper (KONNECT OUTPUT 11)
#define CLAW_LOOSE 1048 // IO bit to sense whether the claw has ejected (KONNECT INPUT 24)
#define TOOL_SENSE 1049 // IO bit to sense whether the a tool is in the spindle (KONNECT INPUT 24)
//---------
#define TOOL_VAR 9 // Tool changer desired new tool Var
#define LAST_TOOL_VAR 7 // Tool changer Last tool position is saved globally in this Var
#define CLAMP_TIME 1.0 // seconds to wait for the clamp/unclamp
#define TOOL_HEIGHT_BIT 1055 //bit to read tool height plate (KONNECT INPUT 31)
#define Z_SAFE_HEIGHT 100 // relative distance in mm to move to clear the top of the tool taper
#define Z_TOOL_RETRACT_SPEED 5000 //speed in counts/second to move spindle up after tool has been ejected
//SEQUENCE OF EVENTS:
// - Remove tool in spindle by going to holder of current tool
// - Rapid to Z Home to clear any work that may be on the table
// - Rapid to TOOL_CHANGE_SAFE_POS to execute a safe negative Z move
// - Approach tool holder by matching Z height of tool flange currently in spindle with tool holder claw
// - After matching height above, approach tool holder by moving to holder X position
// - After matching X position, match tool Y position
// - Move only in Y position until current position matches tool holder position (maybe disable X axis?)
// - Eject tool
// - Turn on CLAW_EJECT bit to remove tool from spindle
// - Turn on SPINDLE_CLEAN bit to remove any debris from taper and tools
// - Wait for time in seconds defined by CLAMP_TIME
// - Read CLAW_LOOSE bit to see whether the tool is loose, to make a safe Z move without destroying tool holder
// - If CLAW_LOOSE bit is high, something has gone wrong;
// halt everything and display message indicating failure
// - Move Z axis up at speed defined by 'Z_TOOL_RETRACT_SPEED', to Z_SAFE_HEIGHT
// - Read TOOL_SENSE bit to see whether the tool has been successfully ejected from the spindle
// - If TOOL_SENSE bit is high, something has gone wrong;
// halt everything and display message indicating failure
// - Move to position of requested tool
// - Rapid move to absolute position of new tool only in X and Y
// - Move to tool Z position at Z_TOOL_RETRACT_SPEED
// - Engage new tool
// - CLAW_EJECT and SPINDLE_CLEAN bits are currently high from tool removal operation
// - Turn off CLAW_EJECT and SPINDLE_CLEAN bits to engage tool
// - Wait for time in seconds defined by CLAMP_TIME
// - Check to see if CLAW_LOOSE and TOOL_SENSE are high; if either are not,
// something has gone wrong; halt everything and display message indicating failure
// - Tool has been engaged
// - Tell KmotionCNC that the current tool is the requested tool
// - Leave tool holder by moving Y axis by the negative value of Y_AXIS_SAFE_DISTANCE
// - Rapid to Z home
// - Tool change has been successful, continue executing G-Code program
// - Optionally, go to position of TOOL_HEIGHT_PLATE to execute a tool offset measuring operation
---------CODE GOES HERE------------